package net.area80.utils {
	import flash.utils.Timer;
	import flash.events.TimerEvent;
	/**
	* Calls specify function on the delay time
	*/
	public class DelayFunction {
		
		private var timer:Timer;
		private var scope:*;
		private var fnc:Function;
		private var args:Array;
		
		public function DelayFunction (delay:int, fnc:Function, args:Array = null, scope:* = null) {
			timer = new Timer(delay, 1);
			this.scope = scope;
			this.fnc = fnc;
			this.args = args;
			timer.addEventListener(TimerEvent.TIMER, timerFunction);
			timer.start();
		}
		private function timerFunction (e:TimerEvent):void {
				try {
				fnc.apply(scope, args);
				} catch (e:Error) {}
				timer.stop();
				timer.removeEventListener(TimerEvent.TIMER, timerFunction);
		}
		public function dispose ():void {
			timer.stop();
			timer.removeEventListener(TimerEvent.TIMER, timerFunction);
		}
	}
	
}